﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace SLTimeZoneHelper.CRM2011.Enums
{
	internal sealed class Helper
	{
		public static IEnumerable<T> GetEnumValues<T>()
		{
			Type type = typeof(T);
			if (!type.IsEnum)
			{
				throw new ArgumentException(string.Format("Type '{0}' is not an enum", type.Name));
			}

			return type.GetFields(BindingFlags.Public | BindingFlags.Static).Where(field => field.IsLiteral).Select(field => (T)field.GetValue(null));

		}

		public static IEnumerable<string> GetEnumStrings<T>()
		{
			Type type = typeof(T);
			if (!type.IsEnum)
			{
				throw new ArgumentException(string.Format("Type '{0}' is not an enum", type.Name));
			}

			return type.GetFields(BindingFlags.Public | BindingFlags.Static).Where(field => field.IsLiteral).Select(field => field.Name);

		}

	}
}